<!--
[{id: '', goodsId: '', name: ''}]
-->
<template>
  <el-dialog
    title="碧划算商品库"
    :visible.sync="showGoodsPop"
    class="el-dialog-edit"
    :close-on-click-modal="false"
  >
    <!-- <el-form label-position="left" label-width="100px" style="width: 100%; padding-left: 20px;">
      <el-form-item label="所选平台：" v-if="count !== 1">
        <div class="el-tag-box">
          <el-tag
            v-for="(goods, index) of goodsCheck"
            :key="goods.id"
            :closable="true"
            @close="delGoods(index)"
          >{{goods.name}}</el-tag>
        </div>
      </el-form-item>
    </el-form>-->

    <el-table
      :data="list"
      v-loading="listLoading"
      element-loading-text="给我一点时间"
      border
      @row-click="clickRow"
    >
      <el-table-column align="center" width="50">
        <template slot-scope="scope">
          <label class="input-radio" v-if="count === 1">
            <input type="radio" :value="{...scope.row}" v-model="goodsCheck" />

            <span></span>
          </label>
          <label class="input-checkbox" v-else>
            <input type="checkbox" :value="{...scope.row}" v-model="goodsCheck" />

            <span></span>
          </label>
        </template>
      </el-table-column>
      <el-table-column align="center" label="平台ID" min-width="110">
        <template slot-scope="scope">
          <div class="text-justify">
            <p v-text="scope.row.id"></p>
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="平台名称" width="110">
        <template slot-scope="scope">
          <span>{{scope.row.name}}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="状态">
        <template slot-scope="scope">
          <span>{{scope.row.enabled===1?'启用' :'禁用'}}</span>
        </template>
      </el-table-column>
    </el-table>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" :loading="btnDisabled" @click="chooseGoods">确定</el-button>
      <el-button @click="close">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getPlayform } from "@/api/bihuasuan/goods";
export default {
  name: "b-goodsPlatform",
  props: {
    check: {
      type: Array,
      default() {
        return [];
      }
    },
    count: {
      type: Number,
      default: 1
    },

    goodId: {
      type: [String, Number],
      default: ""
    }
  },
  data() {
    return {
      list: [],
      showGoodsPop: true,
      goodsCheck: this.check,
      goodsRadio: {},
      listLoading: false,
      btnDisabled: false,
      goodsDetail: {}
    };
  },
  created() {
    this.getList();
    if (this.count === 1 && this.check.length > 0) {
      this.goodsRadio = this.check[0];
    }
  },
  methods: {
    // 获取列表
    async getList() {
      this.listLoading = true;
      try {
        const { data } = await getPlayform();
        this.list = data;

        this.listLoading = false;
      } catch (error) {
        this.list = [];
        this.listLoading = false;
      }
    },
    // 单击行
    clickRow(val) {
      this.goodsCheck = val;
    },
    // 通过tag删除
    // delGoods(index) {
    //   this.goodsCheck.splice(index, 1);
    // },
    // 选择商品
    chooseGoods() {
      if (this.goodsCheck.length < 1) {
        return this.$message.error("请选择平台");
      }
      this.$emit("choose", this.goodsCheck);
      this.close();
    },
    // 关闭弹窗
    close() {
      this.showGoodsPop = false;
      document.body.removeChild(this.$el);
    }
  }
};
</script>
